package org.tgcms.core.dal.appengine.domain;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Version;
import javax.jdo.annotations.VersionStrategy;

import org.tgcms.core.dal.dto.Redirect;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Text;

@PersistenceCapable(detachable="true")
@Version(strategy = VersionStrategy.VERSION_NUMBER, column = "version", extensions = { @Extension(vendorName = "datanucleus", key = "field-name", value = "version") })
public class AppengineRedirect implements AppengineEntity, Redirect {

	@PrimaryKey
	private Key key;

	private Long version;

	@Persistent
	private String name;

	@Persistent
	private String fromUrl;

	@Persistent
	private String toUrl;

	@Persistent
	private Text comment;
	
	public AppengineRedirect(Key key) {
		this.key = key;
	}
	
//	public AppengineRedirect(Redirect t) {
//		this.name = t.getName();
//		this.fromUrl = t.getFromUrl();
//		this.toUrl = t.getToUrl();
//		this.comment = new Text(t.getComment());
//	}
	
	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public Long getVersion() {
		return version;
	}

	public void setVersion(Long version) {
		this.version = version;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFromUrl() {
		return fromUrl;
	}

	public void setFromUrl(String fromUrl) {
		this.fromUrl = fromUrl;
	}

	public String getToUrl() {
		return toUrl;
	}

	public void setToUrl(String toUrl) {
		this.toUrl = toUrl;
	}

	public String getComment() {
		return (comment == null)?null:comment.getValue();
	}

	public void setComment(String comment) {
		this.comment = new Text(comment);
	}

	public Text getCommentText() {
		return comment;
	}

	public void setCommentText(Text comment) {
		this.comment = comment;
	}
	
}
